package edu.hawaii.myisern.action;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

/**
 * Provides test cases.
 * 
 * @author Ka Yee Leung
 * @author Ivan Wu
 * @author Chiao-Fen Zielinski-Liu
 * @author Michal Zielinski
 */
public class TestLogoutActionBean {

  /** Get the test host. */
  private String testHost = System.getProperty("test.host");
  
  /**
   * Tests the login function under normal situations.
   *
   * @throws Exception If problems occur
   */
  @Test
  @SuppressWarnings("deprecation") //TableCell.asText() is httpunit 1.5.3, needed due to Hackystat
  public void testLogoutActionBean() throws Exception {
    HttpUnitOptions.setExceptionsThrownOnScriptError(false);
    HttpUnitOptions.setScriptingEnabled(false);
    
    WebConversation conversation = new WebConversation();
    
    String Url = testHost + "myisern-pink-2.0/index.jsp";
    
    WebResponse response = conversation.getResponse(Url);
    assertEquals("Checking index.jsp retrieval", "MyIsern-Pink-2.0", response.getTitle());
    
    WebForm loginForm = response.getFormWithID("LoginForm");
    WebRequest loginRequest = loginForm.getRequest();
    
    loginRequest.setParameter("username", "username");
    loginRequest.setParameter("password", "password");
    response = conversation.getResponse(loginRequest);
    assertEquals("Checking home.jsp retrieval", "ISERN-2.0", response.getTitle());
   
  }
}